package com.woniu.controller;

import com.woniu.common.CommonResult;
import com.woniu.entity.Announcement;
import com.woniu.service.AnnouncementService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小区物业公告信息(Announcement)表控制层
 *
 * @author makejava
 * @since 2020-03-29 21:50:50
 */
@Controller
@RequestMapping("/announcement")
public class AnnouncementController {
    /**
     * 服务对象
     */
    @Resource
    private AnnouncementService announcementService;

    /**
     * 功能描述: 查询最后三条公告数据
     * @Param: []
     * @Return: com.woniu.common.CommonResult
     * @Author: yanghan
     * @Date: 2020/3/30 0:15
     */
    @GetMapping("/findAll")
    public @ResponseBody CommonResult findAll(){
        try {
            List<Announcement> announcements = announcementService.findAllByThree();
            return CommonResult.success(announcements);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("查询失败");
        }
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Announcement selectOne(Integer id) {
        return this.announcementService.queryById(id);
    }

}